home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 999 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Override a cpp macro?
  5. Date: 10 Jan 1996 20:11:59 GMT
  6. Organization: Los Alamos National Laboratory
  7. Distribution: world
  8. Message-ID: <TANMOY.96Jan10131159@qcd.lanl.gov>
  9. References: <4d0v5r$6fs@oak78.doc.ic.ac.uk>
  10. NNTP-Posting-Host: qcd.lanl.gov
  11. Mime-Version: 1.0
  12. Content-Type: text
  13. In-reply-to: rwmj@doc.ic.ac.uk's message of 10 Jan 1996 18:05:47 -0000
  14.  
  15. --text follows this line--
  16. In article <4d0v5r$6fs@oak78.doc.ic.ac.uk> rwmj@doc.ic.ac.uk (Richard
  17. Jones) writes: 
  18.  
  19.    I'm trying to redefine a cpp macro, but using the old definition. I've got
  20.    a macro defined:
  21.  
  22.        #define m1(a,b) /* some hidden definition of m1 */
  23.  
  24.    and in another file, I want to redefine m1 in terms of the old (unknown)
  25.    definition. Two obvious ways would be:
  26.  
  27.        #define old_m1(a,b) m1(a,b)
  28.        #undef m1
  29.        #define m1(a,b) (old_m1(a,b)+1)
  30.  
  31.    or:
  32.  
  33.        #define new_m1(a,b) (m1(a,b)+1)
  34.        #undef m1
  35.        #define m1(a,b) new_m1(a,b)
  36.  
  37.    But neither works as expected. I've tried variations using the macro:
  38.  
  39. I am sorry. There is no way in standard C to do it. Your compile may
  40. (or more probably will not) provide an extension.
  41.  
  42.        #define expand(a) a
  43.  
  44.    which according to the Gnu info page for (Gnu) cpp should expand the
  45.    argument first. However, no known combination works.
  46.  
  47. It does expand a `first', but `first' at the time when expand(a) is
  48. used, not when it is defined.
  49.  
  50.    What's the way to do this? Surely this is an obvious thing to want to do,
  51.    so there must be some simple point I'm missing?
  52.  
  53. Unfortunately, the C preprocessor has very limited capabilities. No,
  54. it is not an obvious thing to want to do in a C preprocessor.
  55.  
  56. Cheers
  57. Tanmoy
  58. --
  59. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  60. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  61. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  62. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  63. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  64. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  65.